package com.tv.enoguia;

import java.util.ArrayList;

import com.tv.enoguia.adapter.ListBussinessAdapter;
import com.tv.enoguia.adapter.ListFavoritesAdapter;
import com.tv.enoguia.bean.Bussiness;
import com.tv.enoguia.bean.Categories;
import com.tv.enoguia.database.MySQLiteHelper;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class FavouriteActivity extends Activity {

	TextView title;
	ListBussinessAdapter adapter;
	ArrayList<Bussiness> bussinesses = new ArrayList<Bussiness>();
	ListView listFavor;
	MySQLiteHelper db;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_favourite);
		
		db = new MySQLiteHelper(this);
		
		title = (TextView) findViewById(R.id.title);
		listFavor = (ListView) findViewById(R.id.list_favour);
		addData();
		adapter = new ListBussinessAdapter(FavouriteActivity.this, bussinesses);
		listFavor.setAdapter(adapter);
		init();
		
		listFavor.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View v, int position,
					long arg3) {
				Intent t = new Intent(FavouriteActivity.this, DetailBussinessActivity.class);
				Log.i("DATA", "id gui di: "+bussinesses.get(position).getId());
				t.putExtra("id", bussinesses.get(position).getId());
				t.putExtra("liked", 1);
				startActivity(t);
			}
			
		});
		
	}
	
	
	void addData(){
		bussinesses.clear();
		bussinesses = db.getBussinessLike();
	}
	
	void init(){
		title.setText(getString(R.string.txt_favour));
	}


	@Override
	protected void onResume() {
		super.onResume();
		Log.i("STATE", "RESUME");
		addData();
		adapter = new ListBussinessAdapter(FavouriteActivity.this, bussinesses);
		listFavor.setAdapter(adapter);
	}


	@Override
	protected void onPause() {
		super.onPause();
		Log.i("STATE", "PAUSE");
		
		
		
	}
	
	
	
}
